package com.insigma.business.qrcode.soldier.util;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import javax.xml.ws.handler.MessageContext;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Map;

public class RetireXmlUtil {


    public String ybXmlConvertString(String PNAME, String KSSJ, String ZZSJ, String SZCQ, String IDNO) {

        String soapAction = "http://service.neusoft.com";

        String url3 = "http://172.18.103.110:9009/ESBWeb/services/33.1111.zjhz.smzx.ybjybxfxxcx.SynReq@1.0";
        String msgcode = "YB0113";
        String sndMsgId = "1589768236295";
        String MSGTOKEN = "SZW";
        String SNDCODE = "SZW";

        String interactXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<ROOT>" +
                "<HEAD>" +
                "<MSGCODE>" + msgcode + "</MSGCODE>" +
                "<MSGTOKEN>" + MSGTOKEN + "</MSGTOKEN>" +
                "<SNDCODE>" + SNDCODE + "</SNDCODE>" +
                "<SNDMSGID>" + sndMsgId + "</SNDMSGID>" +
                "<USERNAME>fubin</USERNAME>" +
                "<SNDTIME>" + sndMsgId + "</SNDTIME>" +
                "</HEAD>" +
                "<CONTENT>" +
                "<PNAME>" + PNAME + "</PNAME>" +
                "<SZCQ>" + SZCQ + "</SZCQ>" +
                "<KSSJ>" + KSSJ + "</KSSJ>" +
                "<ZZSJ>" + ZZSJ + "</ZZSJ>" +
                "<IDNO>" + IDNO + "</IDNO>" +
                "</CONTENT>" +
                "</ROOT>";
        Service service = new Service();
        String res = null;
        try {

            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(url3);
            call.setOperationName(new QName(soapAction, "receive"));

            call.addParameter(new QName(soapAction, "msgCode"),
                    org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName(soapAction, "sndMsgId"),
                    org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);
            call.addParameter(new QName(soapAction, "interactXml"),
                    org.apache.axis.encoding.XMLType.XSD_STRING,
                    javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);


            org.apache.axis.MessageContext msgContext = call.getMessageContext();
            Map<String, String> headers = new HashMap<>();
            headers.put("appkey", "9jr4cre2i8eoj8iyv68ricmyo");
            headers.put("appSecret", "bsfepp9ieedn3g5trmc74owfu");
            msgContext.setProperty(MessageContext.HTTP_REQUEST_HEADERS, headers);
            call.setUseSOAPAction(true);
            call.setSOAPActionURI(soapAction + "/receive");

            res = String.valueOf(call.invoke(new Object[]{msgcode, sndMsgId, interactXml}));

        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return res;
    }

    public static void main(String[] args) {
        String aa = new RetireXmlUtil().ybXmlConvertString("燕化旗", "20190501",
                "20201205", "330100", "341223199210064519");
        System.out.println(aa);


    }
}

